package com.tarena.csmall.front.web.controller;

import cn.tedu.mall.common.restful.JsonPage;
import cn.tedu.mall.common.restful.JsonResult;
import cn.tedu.mall.pojo.product.vo.AttributeStandardVO;
import cn.tedu.mall.pojo.product.vo.SpuDetailStandardVO;
import cn.tedu.mall.pojo.product.vo.SpuListItemVO;
import cn.tedu.mall.pojo.product.vo.SpuStandardVO;
import com.tarena.csmall.front.web.service.AttributeService;
import com.tarena.csmall.front.web.service.SpuDetailService;
import com.tarena.csmall.front.web.service.SpuService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SpuController {
    /**
     * 根据接口 完成categoryId查询关联spu的
     * list返回
     */
    @Autowired
    private SpuService spuService;
    @GetMapping("/front/spu/list/{catId}")
    public JsonResult<JsonPage<SpuListItemVO>> spuListByCatId(
        @PathVariable Long catId){
        //在业务层封装分页返回对象
        JsonPage<SpuListItemVO> spuList=spuService.spuListByCatId(catId);
        return JsonResult.ok(spuList);
    }
    /**
     * 使用spuId 查询spu表格中一行数据
     */
    @GetMapping("/front/spu/{id}")
    public JsonResult<SpuStandardVO> getSpu(@PathVariable Long id){
        SpuStandardVO spu=spuService.getSpu(id);
        return JsonResult.ok(spu);
    }
    /**
     * 查询spu_detail一行数据
     * 补充spu的完整
     */
    @Autowired
    private SpuDetailService spuDetailService;
    @GetMapping("/front/spu/detail/{spuId}")
    public JsonResult<SpuDetailStandardVO> getSpuDetail(@PathVariable Long spuId){
        SpuDetailStandardVO spuDetail=spuDetailService.getSpuDetail(spuId);
        return JsonResult.ok(spuDetail);
    }
    /**
     * 根据spuId 查询模版对应的所以属性
     */
    @Autowired
    private AttributeService attributeService;
    @GetMapping("/front/spu/template/{spuId}")
    public JsonResult<List<AttributeStandardVO>> getAttributes(@PathVariable Long spuId){
        List<AttributeStandardVO> attributes=attributeService.getAttributes(spuId);
        return JsonResult.ok(attributes);
    }
}
